using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using FireStarter.Base;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.BO.Loaders;
using Habanero.Util;
using Microsoft.Practices.Unity;
using NUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Interfaces;

namespace FireStarterModeller.Test.Logic.Loaders
{
    // ReSharper disable InconsistentNaming
    [TestFixture]
    public class TestDMSolutionPostLoadProcessor
    {
        [SetUp]
        public void SetupTest()
        {
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            TestUtilsDomain.SetupFixture();
        }

        [TearDown]
        public void TearDownTest()
        {
        }


        [Test]
        public void Test_CreateReverseRelationship_WhenRelClassNull_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(null, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_CreateReverseRelationship_WhenRelationshipNull_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMClass relatedClass = GetMockClass();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, null);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_CreateReverseRelationship_ShouldCreateReverseAndLinkRels()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            IDMClass relatedClass = GetMockClass();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNotNull(reverseRelationship);
            Assert.AreSame(reverseRelationship, relationship.ReverseRelationship);
            Assert.AreSame(reverseRelationship.ReverseRelationship, relationship);
        }

        [Test]
        public void Test_CreateReverseRelationship_ShouldSetOwnerClass()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            IDMClass relatedClass = GetMockClass();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.RelatedClass);
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, reverseRelationship.OwnerClass);
        }

        [Test]
        public void Test_CreateReverseRelationship_WhenSingle_ShouldSetAsMultiple()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            SetSingle(relationship);
            IDMClass relatedClass = GetMockClass();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.RelatedClass);
            Assert.IsTrue(relationship.IsSingle, "Should b single");
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Multiple, reverseRelationship.Cardinality);
        }

        [Test]
        public void Test_CreateReverseRelationship_WhenMultiple_ShouldSetAsSingle()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            SetMultiple(relationship);
            IDMClass relatedClass = GetMockClass();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.RelatedClass);
            Assert.IsTrue(relationship.IsMultiple, "Should b multiple");
            Assert.IsFalse(relationship.IsSingle, "Should b multiple");
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, reverseRelationship.Cardinality);
        }
        [Test]
        public void Test_CreateReverseRelationship_WhenCreateSingle_ShouldSetDeleteActionDoNothing()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            SetMultiple(relationship);
            IDMClass relatedClass = GetMockClass();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.RelatedClass);
            Assert.IsTrue(relationship.IsMultiple, "Should b multiple");
            Assert.IsFalse(relationship.IsSingle, "Should b multiple");
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreEqual(DeleteParentAction.DoNothing, reverseRelationship.DeleteAction);
        }

        [Test]
        public void Test_CreateReverseRelationship_ShouldCreateRelName()
        {
            //---------------Set up test pack-------------------
            const string ownerClassName = "SomeClass";
            IDMRelationship relationship = new DMRelationship(null);
            var ownerClass = new DMClass {ClassNameBO = ownerClassName};

            relationship.OwnerClass = ownerClass;
            relationship.Cardinality = Cardinality.Single;
            IDMClass relatedClass = new DMClass();
            IUnityContainer container = new UnityContainer();
            container.RegisterInstance<IDMRelationship>(new DMRelationship(null));
            DMSolutionPostLoadProcessor processor = new DMSolutionPostLoadProcessor(container);
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.RelatedClass);
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreEqual(StringUtilities.Pluralize(ownerClassName), reverseRelationship.RelationshipName);
            Assert.IsFalse(((DMRelationship)reverseRelationship).GenerateCode);
        }
        [Test]
        public void Test_CreateReverseRelationship_ShouldSetGenerateCodeFalse()
        {
            //---------------Set up test pack-------------------
            const string ownerClassName = "SomeClass";
            IDMRelationship relationship = new DMRelationship(null);
            var ownerClass = new DMClass { ClassNameBO = ownerClassName };

            relationship.OwnerClass = ownerClass;
            relationship.Cardinality = Cardinality.Single;
            IDMClass relatedClass = new DMClass();
            IUnityContainer container = new UnityContainer();
            container.RegisterInstance<IDMRelationship>(new DMRelationship(null));
            DMSolutionPostLoadProcessor processor = new DMSolutionPostLoadProcessor(container);
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.RelatedClass);
            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsFalse(reverseRelationship.GenerateCode);
        }

        [Test]
        public void Test_CreatedRelationship_ShouldRetAllCreatedRels()
        {
            //---------------Set up test pack-------------------
            const string ownerClassName = "SomeClass";
            IDMRelationship relationship = new DMRelationship(null);
            var ownerClass = new DMClass { ClassNameBO = ownerClassName };

            relationship.OwnerClass = ownerClass;
            relationship.Cardinality = Cardinality.Single;
            IDMClass relatedClass = new DMClass();
            IUnityContainer container = new UnityContainer();
            container.RegisterInstance<IDMRelationship>(new DMRelationship(null));
            DMSolutionPostLoadProcessor processor = new DMSolutionPostLoadProcessor(container);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var reverseRelationship = processor.CreateReverseRelationship(relatedClass, relationship);
            var createdRelationships = processor.CreatedRelationships;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, createdRelationships.Count);
            Assert.Contains(reverseRelationship, createdRelationships.ToArray());
        }
        [Test]
        public void Test_CreateReverseRelationshipProps_WhenNoRelationshipProps_ShouldRetEmptyCollection()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            SetRelationshipPropWithNoItems(relationship);
            IDMRelationship reverseRelationship = GetReverseRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var reverseRelationshipProps = DMSolutionPostLoadProcessor.CreateReverseRelationshipProps(relationship,
                                                                                                      reverseRelationship);
            //---------------Test Result -----------------------
            Assert.IsEmpty(reverseRelationshipProps);
        }

        [Test]
        public void Test_CreateReverseRelationshipProps_WhenOneRelationshipProps_ShouldRetColWithOne()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            IDMRelationship reverseRelationship = GetReverseRelationship();
            SetRelationshipPropsWithOneItem(relationship);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            var reverseRelationshipProps = DMSolutionPostLoadProcessor.CreateReverseRelationshipProps(relationship,
                                                                                                      reverseRelationship);
            //---------------Test Result -----------------------
            Assert.IsNotEmpty(reverseRelationshipProps);
            Assert.AreEqual(1, reverseRelationshipProps.Count);
        }

        [Test]
        public void Test_CreateReverseRelationshipProps_WhenTwoRelationshipProps_ShouldRetColWithTwo()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            IDMRelationship reverseRelationship = GetReverseRelationship();
            var relProps = SetRelationshipPropsWithTwoItem(relationship);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, relationship.RelationshipProperties.Count);
            Assert.IsNotNullOrEmpty(relProps.First().OwnerPropertyName);
            Assert.IsNotNullOrEmpty(relProps.Last().OwnerPropertyName);
            //---------------Execute Test ----------------------
            var reverseRelProps = DMSolutionPostLoadProcessor.CreateReverseRelationshipProps(relationship,
                                                                                             reverseRelationship);
            //---------------Test Result -----------------------
            Assert.IsNotEmpty(reverseRelProps);
            Assert.AreEqual(2, reverseRelProps.Count);
            AssertReverseRelPropsNames(relProps, reverseRelProps);
        }

        [Test]
        public void Test_CreateReverseRelationshipProps_WhenOneRelationshipProps_ShouldSetUpPropNames()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            IDMRelationship reverseRelationship = GetReverseRelationship();
            var relationshipProp = SetRelationshipPropsWithOneItem(relationship);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            Assert.IsNotNullOrEmpty(relationshipProp.OwnerPropertyName);
            Assert.IsNotNullOrEmpty(relationshipProp.RelatedPropertyName);
            //---------------Execute Test ----------------------
            var reverseRelationshipProps = DMSolutionPostLoadProcessor.CreateReverseRelationshipProps(relationship,
                                                                                                      reverseRelationship);
            //---------------Test Result -----------------------
            var reverseRelProp = reverseRelationshipProps.First();
            AssertRelPropsSetUpAsReverse(relationshipProp, reverseRelProp);
        }

        [Test]
        public void Test_CreateReverseRelationshipProps_WhenOneRelationshipProps_ShouldSetRelationshpOnRelProp()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = new DMRelationship();
            IDMRelationship reverseRelationship = new DMRelationship();
            var relationshipProp = CreateRandomRelProp();
            relationship.RelationshipProperties.Add(relationshipProp);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            Assert.IsNotNullOrEmpty(relationshipProp.OwnerPropertyName);
            Assert.IsNotNullOrEmpty(relationshipProp.RelatedPropertyName);
            //---------------Execute Test ----------------------
            var reverseRelationshipProps = DMSolutionPostLoadProcessor.CreateReverseRelationshipProps(relationship,
                                                                                                      reverseRelationship);
            //---------------Test Result -----------------------
            var reverseRelProp = reverseRelationshipProps.First();
            Assert.AreSame(reverseRelationship, reverseRelProp.Relationship);
        }

        [Test]
        public void Test_LinkRelPropsToProps_WhenDMPropExists_ShouldSetOwnerProp()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            var relationshipProp = SetRelationshipPropsWithOneItem(relationship);

            var ownerPropertyName = relationshipProp.OwnerPropertyName;
            IDMClass ownerClass = GetMockClassWithOneProp(ownerPropertyName);

            var ownerProp = ownerClass.GetDMProperty(ownerPropertyName);
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, relationship.RelationshipProperties.Count);
            Assert.IsNotNullOrEmpty(ownerPropertyName);

            Assert.IsNotNull(ownerProp);

            Assert.IsNull(relationshipProp.OwnerProperty);
            //---------------Execute Test ----------------------
            processor.LinkRelPropToProperties(relationship, ownerClass);
            //---------------Test Result -----------------------
            Assert.AreSame(relationshipProp, relationship.RelationshipProperties.First());
            Assert.AreSame(ownerProp, relationshipProp.OwnerProperty);
        }

        [Test]
        public void Test_LinkRelPropsToProps_WhenRelationshipNull_ShouldDoNothing()
        {
            //---------------Set up test pack-------------------
            IDMClass ownerClass = GetMockClass();

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            processor.LinkRelPropToProperties(null, ownerClass);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If you get here all is OK");
        }

        [Test]
        public void Test_LinkRelPropsToProps_WhenOwnerClassNull_ShouldDoNothing()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            processor.LinkRelPropToProperties(relationship, null);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If you get here all is OK");
        }

        [Test]
        public void Test_LinkRelPropsToProps_WhenCompositeFK_WhenDMPropExists_ShouldSetOwnerProps()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            var relationshipProps = SetRelationshipPropsWithTwoItem(relationship);
            var relationshipProp1 = relationshipProps.First();
            var ownerPropertyName1 = relationshipProp1.OwnerPropertyName;
            var relationshipProp2 = relationshipProps.Last();
            var ownerPropertyName2 = relationshipProp2.OwnerPropertyName;

            IDMClass ownerClass = GetMockClassWithTwoProp(ownerPropertyName1, ownerPropertyName2);

            var ownerProp1 = ownerClass.GetDMProperty(ownerPropertyName1);
            var ownerProp2 = ownerClass.GetDMProperty(ownerPropertyName2);
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, relationship.RelationshipProperties.Count);
            Assert.IsNotNullOrEmpty(ownerPropertyName1);
            Assert.IsNotNullOrEmpty(ownerPropertyName2);

            Assert.IsNotNull(ownerProp1);
            Assert.IsNotNull(ownerProp2);

            Assert.IsNull(relationshipProp1.OwnerProperty);
            Assert.IsNull(relationshipProp2.OwnerProperty);
            //---------------Execute Test ----------------------
            processor.LinkRelPropToProperties(relationship, ownerClass);
            //---------------Test Result -----------------------
            Assert.AreSame(relationshipProp1, relationship.RelationshipProperties.First());
            Assert.AreSame(relationshipProp2, relationship.RelationshipProperties.Last());
            Assert.AreSame(ownerProp1, relationshipProp1.OwnerProperty);
            Assert.AreSame(ownerProp2, relationshipProp2.OwnerProperty);
        }

        [Test]
        public void Test_FindReverseRelationship_RelatedClassNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(null, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_RelationshipNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMClass relatedClass = GetMockClass();

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, null);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_WhenNonExists_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            IDMClass relatedClass = GetMockClass();
            SetRelationshipsToEmpty(relatedClass);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationship.ReverseRelationshipName);
            Assert.AreEqual(0, relatedClass.RelationshipsDM.Count);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_WhenItsRelNameEqReverseRelName_ShouldReturnFoundRelationship()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            var reverseRelationshipName = relationship.ReverseRelationshipName;
            IDMClass relatedClass = GetMockClass();
            DMRelationship expectedRevRel = SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, reverseRelationshipName, null);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(reverseRelationshipName);
            Assert.AreEqual(1, relatedClass.RelationshipsDM.Count);
            Assert.IsNotNull(expectedRevRel);


            Assert.AreEqual(reverseRelationshipName, expectedRevRel.RelationshipName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedRevRel, reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_WhenItsRevRelNameEqRelName_ShouldReturnFoundRelationship()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            var relationshipName = relationship.RelationshipName;
            IDMClass relatedClass = GetMockClass();
            DMRelationship expectedRevRel = SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), relationshipName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationshipName);
            Assert.AreEqual(1, relatedClass.RelationshipsDM.Count);
            Assert.IsNotNull(expectedRevRel);

            Assert.AreEqual(relationshipName, expectedRevRel.ReverseRelationshipName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedRevRel, reverseRelationship);
        }
        [Test]
        public void Test_FindReverseRelationship_WhenRevRelNameEqRelName_ButOwnClassNameNotMatch_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            var relationshipName = relationship.RelationshipName;
            IDMClass relatedClass = GetMockClass();
            DMRelationship expectedRevRel = SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, GetRandomString(), relationship.ReverseRelationshipName, relationshipName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationshipName);
            Assert.AreEqual(1, relatedClass.RelationshipsDM.Count);
            Assert.IsNotNull(expectedRevRel);

            Assert.AreEqual(relationshipName, expectedRevRel.ReverseRelationshipName);
            Assert.AreEqual(relationship.ReverseRelationshipName, expectedRevRel.RelationshipName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_HasItemsAndOnlyOneMatches_ShouldReturnFoundRelationship()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            var relationshipName = relationship.RelationshipName;
            IDMClass relatedClass = GetMockClass();
            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), GetRandomString());
            DMRelationship expectedRevRel = AddRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), relationshipName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);
            Assert.IsNotNull(expectedRevRel);
            Assert.AreEqual(relationship.OwnerClassName, expectedRevRel.RelatedClassName);
            Assert.AreEqual(relationshipName, expectedRevRel.ReverseRelationshipName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedRevRel, reverseRelationship);
        }
        [Test]
        public void Test_FindReverseRelationship_HasItemsAndOnlyOneMatches_ButRelatedClassNameCapitalisedIncorrectly_ShouldReturnFoundRelationship()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            var relationshipName = relationship.RelationshipName;
            IDMClass relatedClass = GetMockClass();
            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName.ToLower(), GetRandomString(), GetRandomString());
            DMRelationship expectedRevRel = AddRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName.ToLower(), GetRandomString(), relationshipName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);
            Assert.IsNotNull(expectedRevRel);
            Assert.AreNotEqual(relationship.OwnerClassName, expectedRevRel.RelatedClassName);
            Assert.AreEqual(relationship.OwnerClassName.ToUpper(), expectedRevRel.RelatedClassName.ToUpper());
            Assert.AreEqual(relationshipName, expectedRevRel.ReverseRelationshipName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedRevRel, reverseRelationship);
        }
        [Test]
        public void Test_FindReverseRelationship_RelClassNameMatchesButAssemblyNot_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            var relationshipName = relationship.RelationshipName;
            IDMClass relatedClass = GetMockClass();
            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), GetRandomString());
            DMRelationship expectedRevRel = AddRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), relationshipName);
            expectedRevRel.RelatedAssemblyName = GetRandomString();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.OwnerClassAssemblyName);
            Assert.IsNotNullOrEmpty(expectedRevRel.RelatedAssemblyName);
            Assert.IsNotNullOrEmpty(relationship.OwnerClassName);
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);
            Assert.IsNotNull(expectedRevRel);


            Assert.AreEqual(relationshipName, expectedRevRel.ReverseRelationshipName);
            Assert.AreEqual(relationship.OwnerClassName, expectedRevRel.RelatedClassName);
            Assert.AreNotEqual(relationship.OwnerClassAssemblyName, expectedRevRel.RelatedAssemblyName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }
        [Test]
        public void Test_FindReverseRelationship_RelClassAndAssemblyMatchesButAssemblyCapitalisationWrong_ShouldRetItem()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            var relationshipName = relationship.RelationshipName;
            IDMClass relatedClass = GetMockClass();
            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), GetRandomString());
            DMRelationship expectedRevRel = AddRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), relationshipName);
            expectedRevRel.RelatedAssemblyName = relationship.OwnerClassAssemblyName.ToLower();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.OwnerClassAssemblyName);
            Assert.IsNotNullOrEmpty(expectedRevRel.RelatedAssemblyName);
            Assert.IsNotNullOrEmpty(relationship.OwnerClassName);
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);
            Assert.IsNotNull(expectedRevRel);


            Assert.AreEqual(relationshipName, expectedRevRel.ReverseRelationshipName);
            Assert.AreEqual(relationship.OwnerClassName, expectedRevRel.RelatedClassName);
            Assert.AreNotEqual(relationship.OwnerClassAssemblyName, expectedRevRel.RelatedAssemblyName);
            Assert.AreEqual(relationship.OwnerClassAssemblyName.ToUpper(), expectedRevRel.RelatedAssemblyName.ToUpper());
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedRevRel, reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_HasItemsAndNonMatches_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            var relationshipName = relationship.RelationshipName;
            IDMClass relatedClass = GetMockClass();
            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), GetRandomString());
            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), GetRandomString());

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(relationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_NoReverseRelDefinedButMatchesRelProps_ShouldRetReverseRel()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            IDMRelationshipProperty ownerRelProp = AddRelProp(relationship);


            IDMClass relatedClass = GetMockClass();
            IDMRelationship expectedReverseRel = SetMockRelationship(relationship.OwnerClassAssemblyName, relationship.OwnerClassName, relatedClass, GetRandomString(),
                                                                     GetRandomString());
            expectedReverseRel.ReverseRelationshipName = null;
            AddRelProp(expectedReverseRel, ownerRelProp.RelatedPropertyName, ownerRelProp.OwnerPropertyName);
            expectedReverseRel.RelatedClassName = relationship.OwnerClassName;
            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), null);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNullOrEmpty(relationship.ReverseRelationshipName);
            Assert.IsNullOrEmpty(expectedReverseRel.ReverseRelationshipName);
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(expectedReverseRel.RelationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);

            Assert.IsNull(relationship.ReverseRelationship);
            Assert.IsNull(expectedReverseRel.ReverseRelationship);
            Assert.AreSame(expectedReverseRel.RelatedClassName, relationship.OwnerClassName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNotNull(reverseRelationship);
            Assert.AreSame(expectedReverseRel, reverseRelationship);
        }
        [Test]
        public void Test_FindReverseRelationship_NoReverseRelMatchesRelProps_NotMatchesRelatedClass_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            IDMRelationshipProperty ownerRelProp = AddRelProp(relationship);


            IDMClass relatedClass = GetMockClass();
            IDMRelationship expectedReverseRel = SetMockRelationship(relationship.OwnerClassAssemblyName, GetRandomString(), relatedClass, GetRandomString(),
                                                                     GetRandomString());
            expectedReverseRel.ReverseRelationshipName = null;
            AddRelProp(expectedReverseRel, ownerRelProp.RelatedPropertyName, ownerRelProp.OwnerPropertyName);

            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), null);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNullOrEmpty(relationship.ReverseRelationshipName);
            Assert.IsNullOrEmpty(expectedReverseRel.ReverseRelationshipName);
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(expectedReverseRel.RelationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);

            Assert.IsNull(relationship.ReverseRelationship);
            Assert.IsNull(expectedReverseRel.ReverseRelationship);
            Assert.AreNotSame(expectedReverseRel.RelatedClassName, relationship.OwnerClassName);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_WhenRevRelNameNotNull_AndPropsMatch_ShouldRetNull()
        {
            //If either the relationship or the reverse relationship have a named
            //reverse relationship from the XML Loader then you should never link based
            // on RelProps
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            IDMRelationshipProperty ownerRelProp = AddRelProp(relationship);


            IDMClass relatedClass = GetMockClass();
            IDMRelationship expectedReverseRel = SetMockRelationship(relationship.OwnerClassAssemblyName, relationship.OwnerClassName, relatedClass, GetRandomString(),
                                                                     GetRandomString());
            expectedReverseRel.ReverseRelationshipName = null;
            AddRelProp(expectedReverseRel, ownerRelProp.RelatedPropertyName, ownerRelProp.OwnerPropertyName);

            SetRelationship(relatedClass, relationship.OwnerClassAssemblyName, relationship.OwnerClassName, GetRandomString(), null);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNullOrEmpty(expectedReverseRel.ReverseRelationshipName);
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(expectedReverseRel.RelationshipName);

            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);


            Assert.IsNotNullOrEmpty(relationship.ReverseRelationshipName);
            Assert.AreNotEqual(expectedReverseRel.ReverseRelationshipName, relationship.RelationshipName);
            Assert.AreNotEqual(expectedReverseRel.RelationshipName, relationship.ReverseRelationshipName);
            Assert.IsNull(relationship.ReverseRelationship);
            Assert.IsNull(expectedReverseRel.ReverseRelationship);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_NoReverseRelDefinedAndPropsDoNotMatch_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            IDMRelationshipProperty ownerRelProp = AddRelProp(relationship);


            IDMClass relatedClass = GetMockClass();
            IDMRelationship reverseRel1 = SetMockRelationship(relationship.OwnerClassAssemblyName, relationship.OwnerClassName, relatedClass, GetRandomString(), null);
            AddRelProp(reverseRel1, ownerRelProp.RelatedPropertyName, GetRandomString());

            var reverseRel2 = SetMockRelationship(relationship.OwnerClassAssemblyName, relationship.OwnerClassName, relatedClass, GetRandomString(), null);
            AddRelProp(reverseRel2, ownerRelProp.RelatedPropertyName, GetRandomString());
            AddRelProp(reverseRel2, GetRandomString(), GetRandomString());

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNullOrEmpty(relationship.ReverseRelationshipName);
            Assert.IsNullOrEmpty(reverseRel1.ReverseRelationshipName);
            Assert.IsNotNullOrEmpty(relationship.RelationshipName);
            Assert.IsNotNullOrEmpty(reverseRel1.RelationshipName);
            Assert.AreEqual(2, relatedClass.RelationshipsDM.Count);

            Assert.IsNull(relationship.ReverseRelationship);
            Assert.IsNull(reverseRel1.ReverseRelationship);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(reverseRelationship);
        }

        [Test]
        public void Test_FindReverseRelationship_WhenRevRelNamesNull_AndCompositePropsMatch_ShouldRetRevRel()
        {
            //If either the relationship or the reverse relationship have a named
            //reverse relationship from the XML Loader then you should never link based
            // on RelProps
            IDMRelationship relationship = GetMockRelationshipWithNamesSet();
            relationship.ReverseRelationshipName = null;
            IDMRelationshipProperty ownerRelProp = AddRelProp(relationship);
            IDMRelationshipProperty ownerRelProp2 = AddRelProp(relationship);


            IDMClass relatedClass = GetMockClass();
            IDMRelationship expectedReverseRel = SetMockRelationship(relationship.OwnerClassAssemblyName, relationship.OwnerClassName, relatedClass, GetRandomString(), null);
            expectedReverseRel.RelatedClassName = relationship.OwnerClassName;
            AddRelProp(expectedReverseRel, ownerRelProp.RelatedPropertyName, ownerRelProp.OwnerPropertyName);
            AddRelProp(expectedReverseRel, ownerRelProp2.RelatedPropertyName, ownerRelProp2.OwnerPropertyName);

            SetMockRelationship(relationship.OwnerClassAssemblyName, relationship.OwnerClassName, relatedClass, GetRandomString(), null);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------

            Assert.IsNullOrEmpty(expectedReverseRel.ReverseRelationshipName);
            Assert.AreEqual(2, relationship.RelationshipProperties.Count);
            Assert.AreEqual(2, expectedReverseRel.RelationshipProperties.Count);
            Assert.AreNotEqual(expectedReverseRel.ReverseRelationshipName, relationship.RelationshipName);
            Assert.AreNotEqual(expectedReverseRel.RelationshipName, relationship.ReverseRelationshipName);
            Assert.IsNull(relationship.ReverseRelationship);
            Assert.IsNull(expectedReverseRel.ReverseRelationship);
            //---------------Execute Test ----------------------
            IDMRelationship reverseRelationship = processor.FindReverseRelationship(relatedClass, relationship);
            //---------------Test Result -----------------------
            Assert.IsNotNull(reverseRelationship);
            Assert.AreSame(expectedReverseRel, reverseRelationship);
        }

        [Test]
        public void Test_FindClass_RelationshipNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = null;
            List<IDMClass> col = new List<IDMClass>();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship);
            Assert.IsNotNull(col);
            //---------------Execute Test ----------------------
            IDMClass foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelatedClass);
        }

        [Test]
        public void Test_FindClass_ClassesNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();
            List<IDMClass> col = null;
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            Assert.IsNull(col);
            //---------------Execute Test ----------------------
            var foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelatedClass);
        }

        [Test]
        public void Test_FindClass_WhenWithNullName_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetMockRelationship();

            List<IDMClass> col = new List<IDMClass>();

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            Assert.IsEmpty(col);
            //---------------Execute Test ----------------------
            var relatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(relatedClass);
        }
        [Test]
        public void Test_FindClass_WhenNonExists_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetRelationshipWithClassNameAssembly();
            List<IDMClass> col = new List<IDMClass>();

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship);
            Assert.IsEmpty(col);
            //---------------Execute Test ----------------------
            var relatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(relatedClass);
        }

        [Test]
        public void Test_FindClass_WhenClassNameAndAssemblyMatch_ShouldReturnFoundClass()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetRelationshipWithClassNameAssembly();
            var relatedClassName = relationship.RelatedClassName;
            var relatedAssemblyName = relationship.RelatedAssemblyName;

            List<IDMClass> col = GetColWithOneRelatedClass(relatedAssemblyName, relatedClassName);

            var relatedClass = col.FirstOrDefault();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relatedClassName);
            Assert.IsNotNullOrEmpty(relatedAssemblyName);
            Assert.IsNotNull(relatedClass);


            Assert.AreEqual(1, col.Count());
            Assert.AreEqual(relatedClassName, relatedClass.ClassNameBO);
            Assert.AreEqual(relatedAssemblyName, relatedClass.AssemblyName);
            //---------------Execute Test ----------------------
            var foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, foundRelatedClass);
        }
        [Test]
        public void Test_FindClass_WhenClassNameAndAssemblyMatchButNotCapitalisedCorrectly_ShouldReturnFoundClass()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetRelationshipWithClassNameAssembly();
            var relatedClassName = relationship.RelatedClassName;
            var relatedAssemblyName = relationship.RelatedAssemblyName;

            List<IDMClass> col = GetColWithOneRelatedClass(relatedAssemblyName.ToLower(), relatedClassName.ToLower());

            var relatedClass = col.FirstOrDefault();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relatedClassName);
            Assert.IsNotNullOrEmpty(relatedAssemblyName);
            Assert.IsNotNull(relatedClass);


            Assert.AreEqual(1, col.Count());
            Assert.AreNotEqual(relatedClassName, relatedClass.ClassNameBO);
            Assert.AreNotEqual(relatedAssemblyName, relatedClass.AssemblyName);
            //---------------Execute Test ----------------------
            var foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, foundRelatedClass);
        }

        private static IDMRelationship GetRelationshipWithClassNameAssembly()
        {
            IDMRelationship relationship = GetMockRelationship();
            relationship.RelatedClassName = GetRandomString();
            relationship.RelatedAssemblyName = GetRandomString();
            return relationship;
        }

        [Test]
        public void Test_FindClass_WhenClassNameMatchesButAssemblyNot_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetRelationshipWithClassNameAssembly();
            var relatedClassName = relationship.RelatedClassName;
            var relatedAssemblyName = relationship.RelatedAssemblyName;

            List<IDMClass> col = GetColWithOneRelatedClass(GetRandomString(), relatedClassName);
            var relatedClass = col.FirstOrDefault();

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relatedClassName);
            Assert.IsNotNullOrEmpty(relatedAssemblyName);
            Assert.IsNotNull(relatedClass);

            Assert.AreEqual(1, col.Count());
            Assert.AreNotEqual(relatedAssemblyName, relatedClass.AssemblyName);
            Assert.AreEqual(relatedClassName, relatedClass.ClassNameBO);
            //---------------Execute Test ----------------------
            var foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelatedClass);
        }

        [Test]
        public void Test_FindClass_WhenAssemblyMatchesClassNot_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetRelationshipWithClassNameAssembly();
            var relatedClassName = relationship.RelatedClassName;
            var relatedAssemblyName = relationship.RelatedAssemblyName;

            List<IDMClass> col = GetColWithOneRelatedClass(relatedAssemblyName, GetRandomString());
            var relatedClass = col.FirstOrDefault();

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relatedClassName);
            Assert.IsNotNullOrEmpty(relatedAssemblyName);
            Assert.IsNotNull(relatedClass);

            Assert.AreEqual(1, col.Count());
            Assert.Contains(relatedClass, col);
            Assert.AreEqual(relatedAssemblyName, relatedClass.AssemblyName);
            Assert.AreNotEqual(relatedClassName, relatedClass.ClassNameBO);
            //---------------Execute Test ----------------------
            var foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelatedClass);
        }

        [Test]
        public void Test_FindClass_HasManyItemsAndNonMatches_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetRelationshipWithClassNameAssembly();
            var relatedClassName = relationship.RelatedClassName;
            var relatedAssemblyName = relationship.RelatedAssemblyName;

            List<IDMClass> col = GetColWithOneRelatedClass(relatedAssemblyName, GetRandomString());
            var relatedClass1 = GetMockClass(relatedAssemblyName, GetRandomString());
            col.Add(relatedClass1);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relatedClassName);
            Assert.IsNotNullOrEmpty(relatedAssemblyName);

            Assert.AreEqual(2, col.Count());
            //---------------Execute Test ----------------------
            var foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelatedClass);
        }

        [Test]
        public void Test_FindClass_HasManyItemsAndOneMatches_ShouldRetItem()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = GetRelationshipWithClassNameAssembly();
            var relatedClassName = relationship.RelatedClassName;
            var relatedAssemblyName = relationship.RelatedAssemblyName;

            List<IDMClass> col = GetColWithOneRelatedClass(relatedAssemblyName, GetRandomString());
            var relatedClass = GetMockClass(relatedAssemblyName, relatedClassName);
            col.Add(relatedClass);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(relatedClassName);
            Assert.IsNotNullOrEmpty(relatedAssemblyName);

            Assert.AreEqual(2, col.Count());
            Assert.AreEqual(relatedAssemblyName, relatedClass.AssemblyName);
            Assert.AreEqual(relatedClassName, relatedClass.ClassNameBO);
            //---------------Execute Test ----------------------
            var foundRelatedClass = processor.FindClass(col, relationship);
            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, foundRelatedClass);
        }

        [Test]
        public void Test_SetRevRel_ShouldSetBothRelsReverseRel()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = new DMRelationship(null);
            IDMRelationship reverseRel = new DMRelationship(null);
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.ReverseRelationship);
            Assert.IsNull(reverseRel.ReverseRelationship);
            //---------------Execute Test ----------------------
            DMSolutionPostLoadProcessor.SetReverseRelationship(relationship, reverseRel);
            //---------------Test Result -----------------------
            Assert.AreSame(reverseRel, relationship.ReverseRelationship);
            Assert.AreSame(relationship, reverseRel.ReverseRelationship);
        }

        [Test]
        public void Test_SetRevRel_WhenAlreadyHaveRevRels_ShouldSetBothRelsReverseRel()
        {
            //---------------Set up test pack-------------------
            IDMRelationship relationship = new DMRelationship();
            IDMRelationship reverseRel = new DMRelationship();

            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship.ReverseRelationship);
            Assert.IsNotNull(reverseRel.ReverseRelationship);
            //---------------Execute Test ----------------------
            DMSolutionPostLoadProcessor.SetReverseRelationship(relationship, reverseRel);
            //---------------Test Result -----------------------
            Assert.AreSame(reverseRel, relationship.ReverseRelationship);
            Assert.AreSame(relationship, reverseRel.ReverseRelationship);
        }

        [Test]
        public void Test_SetRevRelProp_ShouldSetBothRevRelProp()
        {
            //---------------Set up test pack-------------------
            DMRelationshipProperty relProp = new DMRelationshipProperty(null);
            DMRelationshipProperty reverseRelProp = new DMRelationshipProperty(null);
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relProp.ReverseRelationshipProperty);
            Assert.IsNull(reverseRelProp.ReverseRelationshipProperty);
            //---------------Execute Test ----------------------
            processor.SetReverseRelationshipProperty(relProp, reverseRelProp);
            //---------------Test Result -----------------------
            Assert.AreSame(reverseRelProp, relProp.ReverseRelationshipProperty);
            Assert.AreSame(relProp, reverseRelProp.ReverseRelationshipProperty);
        }

        [Test]
        public void Test_SetRevRelProp_WhenAlreadyHaveRevRelProps_ShouldSetBothRevRelProp()
        {
            //---------------Set up test pack-------------------
            DMRelationshipProperty relProp = new DMRelationshipProperty();
            DMRelationshipProperty reverseRelProp = new DMRelationshipProperty();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relProp.ReverseRelationshipProperty);
            Assert.IsNotNull(reverseRelProp.ReverseRelationshipProperty);
            //---------------Execute Test ----------------------
            processor.SetReverseRelationshipProperty(relProp, reverseRelProp);
            //---------------Test Result -----------------------
            Assert.AreSame(reverseRelProp, relProp.ReverseRelationshipProperty);
            Assert.AreSame(relProp, reverseRelProp.ReverseRelationshipProperty);
        }

        [Test]
        public void Test_FindReverseRelationshipProperty_RelationshipPropNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = null;
            IEnumerable<IDMRelationshipProperty> relProps = new List<IDMRelationshipProperty>();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relationshipProperty);
            //---------------Execute Test ----------------------
            var foundRelProp = processor.FindReverseRelationshipProperty(relProps, relationshipProperty);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelProp);
        }

        [Test]
        public void Test_FindReverseRelationshipProperty_RelPropsNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = MockRepository.GenerateStub<IDMRelationshipProperty>();
            IEnumerable<IDMRelationshipProperty> relProps = null;
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNull(relProps);
            Assert.IsNotNull(relationshipProperty);
            //---------------Execute Test ----------------------
            var foundRelProp = processor.FindReverseRelationshipProperty(relProps, relationshipProperty);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelProp);
        }

        [Test]
        public void Test_FindReverseRelationshipProperty_WhenNonExists_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = MockRepository.GenerateStub<IDMRelationshipProperty>();
            IEnumerable<IDMRelationshipProperty> relProps = new List<IDMRelationshipProperty>();
            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationshipProperty);
            Assert.AreEqual(0, relProps.Count());
            //---------------Execute Test ----------------------
            var foundRelProp = processor.FindReverseRelationshipProperty(relProps, relationshipProperty);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelProp);
        }

        [Test]
        public void Test_FindReverseRelationshipProperty_WhenOwnerPropNameAndRelPropNameMatch_ShouldRetFoundRelationship
            ()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = GetMockRelationshipProperty();

            var ownerPropertyName = relationshipProperty.OwnerPropertyName;
            var relatedPropertyName = relationshipProperty.RelatedPropertyName;

            List<IDMRelationshipProperty> relProps = new List<IDMRelationshipProperty>();
            IDMRelationshipProperty relatedRelProp = AddRelProp(relProps, relatedPropertyName, ownerPropertyName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(ownerPropertyName);
            Assert.IsNotNullOrEmpty(relatedPropertyName);
            Assert.AreEqual(1, relProps.Count());

            Assert.AreEqual(ownerPropertyName, relatedRelProp.RelatedPropertyName);
            Assert.AreEqual(relatedPropertyName, relatedRelProp.OwnerPropertyName);
            //---------------Execute Test ----------------------
            var foundRelProp = processor.FindReverseRelationshipProperty(relProps, relationshipProperty);
            //---------------Test Result -----------------------
            Assert.AreSame(relatedRelProp, foundRelProp);
        }

        [Test]
        public void Test_FindReverseRelationshipProperty_WhenOnlyOwnerPropNameMatches_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = GetMockRelationshipProperty();

            var ownerPropertyName = relationshipProperty.OwnerPropertyName;
            var relatedPropertyName = relationshipProperty.RelatedPropertyName;

            List<IDMRelationshipProperty> relProps = new List<IDMRelationshipProperty>();
            IDMRelationshipProperty relatedRelProp = AddRelProp(relProps, relatedPropertyName, GetRandomString());

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(ownerPropertyName);
            Assert.IsNotNullOrEmpty(relatedPropertyName);
            Assert.AreEqual(1, relProps.Count());

            Assert.AreNotEqual(ownerPropertyName, relatedRelProp.RelatedPropertyName);
            Assert.AreEqual(relatedPropertyName, relatedRelProp.OwnerPropertyName);
            //---------------Execute Test ----------------------
            var foundRelProp = processor.FindReverseRelationshipProperty(relProps, relationshipProperty);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelProp);
        }

        [Test]
        public void Test_FindReverseRelationshipProperty_WhenOnlyRelatedPropNameMatches_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = GetMockRelationshipProperty();

            var ownerPropertyName = relationshipProperty.OwnerPropertyName;
            var relatedPropertyName = relationshipProperty.RelatedPropertyName;

            List<IDMRelationshipProperty> relProps = new List<IDMRelationshipProperty>();
            IDMRelationshipProperty relatedRelProp = AddRelProp(relProps, GetRandomString(), ownerPropertyName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(ownerPropertyName);
            Assert.IsNotNullOrEmpty(relatedPropertyName);
            Assert.AreEqual(1, relProps.Count());

            Assert.AreEqual(ownerPropertyName, relatedRelProp.RelatedPropertyName);
            Assert.AreNotEqual(relatedPropertyName, relatedRelProp.OwnerPropertyName);
            //---------------Execute Test ----------------------
            var foundRelProp = processor.FindReverseRelationshipProperty(relProps, relationshipProperty);
            //---------------Test Result -----------------------
            Assert.IsNull(foundRelProp);
        }

        [Test]
        public void Test_FindReverseRelationshipProperty_WhenMultipleItemsOneMatches_ShouldRetFoundRelationship()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = GetMockRelationshipProperty();

            var ownerPropertyName = relationshipProperty.OwnerPropertyName;
            var relatedPropertyName = relationshipProperty.RelatedPropertyName;

            List<IDMRelationshipProperty> relProps = new List<IDMRelationshipProperty>();
            AddRelProp(relProps, relatedPropertyName, GetRandomString());
            IDMRelationshipProperty relatedRelProp = AddRelProp(relProps, relatedPropertyName, ownerPropertyName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(ownerPropertyName);
            Assert.IsNotNullOrEmpty(relatedPropertyName);
            Assert.AreEqual(2, relProps.Count());

            Assert.AreEqual(ownerPropertyName, relatedRelProp.RelatedPropertyName);
            Assert.AreEqual(relatedPropertyName, relatedRelProp.OwnerPropertyName);
            //---------------Execute Test ----------------------
            var foundRelProp = processor.FindReverseRelationshipProperty(relProps, relationshipProperty);
            //---------------Test Result -----------------------
            Assert.AreSame(relatedRelProp, foundRelProp);
        }

        [Test]
        public void Test_SetAllRelationshipProperties_WhenSingleAndMatch_ShouldSet()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = GetMockRelationshipProperty();
            IList<IDMRelationshipProperty> ownerRelProps = new List<IDMRelationshipProperty>();
            ownerRelProps.Add(relationshipProperty);

            var ownerPropertyName = relationshipProperty.OwnerPropertyName;
            var relatedPropertyName = relationshipProperty.RelatedPropertyName;

            IList<IDMRelationshipProperty> reverseRelProps = new List<IDMRelationshipProperty>();
            IDMRelationshipProperty relatedRelProp = AddRelProp(reverseRelProps, relatedPropertyName, ownerPropertyName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(ownerPropertyName);
            Assert.IsNotNullOrEmpty(relatedPropertyName);
            Assert.AreEqual(1, reverseRelProps.Count());

            Assert.AreEqual(ownerPropertyName, relatedRelProp.RelatedPropertyName);
            Assert.AreEqual(relatedPropertyName, relatedRelProp.OwnerPropertyName);
            //---------------Execute Test ----------------------
            processor.SetAllReverseRelProps(ownerRelProps, reverseRelProps);
            //---------------Test Result -----------------------
            Assert.AreSame(relationshipProperty, relatedRelProp.ReverseRelationshipProperty);
            Assert.AreSame(relatedRelProp, relationshipProperty.ReverseRelationshipProperty);
        }

        [Test]
        public void Test_SetAllRelationshipProperties_WhenSingleAndNotMatch_ShouldNotSet()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty relationshipProperty = GetMockRelationshipProperty();
            IList<IDMRelationshipProperty> ownerRelProps = new List<IDMRelationshipProperty> {relationshipProperty};

            var ownerPropertyName = relationshipProperty.OwnerPropertyName;
            var relatedPropertyName = relationshipProperty.RelatedPropertyName;

            IList<IDMRelationshipProperty> reverseRelProps = new List<IDMRelationshipProperty>();
            IDMRelationshipProperty relatedRelProp = AddRelProp(reverseRelProps, GetRandomString(), ownerPropertyName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.IsNotNullOrEmpty(ownerPropertyName);
            Assert.IsNotNullOrEmpty(relatedPropertyName);
            Assert.AreEqual(1, reverseRelProps.Count());

            Assert.AreEqual(ownerPropertyName, relatedRelProp.RelatedPropertyName);
            Assert.AreNotEqual(relatedPropertyName, relatedRelProp.OwnerPropertyName);
            //---------------Execute Test ----------------------
            processor.SetAllReverseRelProps(ownerRelProps, reverseRelProps);
            //---------------Test Result -----------------------
            Assert.AreNotSame(relationshipProperty, relatedRelProp.ReverseRelationshipProperty);
            Assert.AreNotSame(relatedRelProp, relationshipProperty.ReverseRelationshipProperty);
        }

        [Test]
        public void Test_SetAllRelationshipProperties_WhenCompositeAndMatch_ShouldSet()
        {
            //---------------Set up test pack-------------------
            IDMRelationshipProperty ownerRelProp1 = GetMockRelationshipProperty();
            IList<IDMRelationshipProperty> ownerRelProps = new List<IDMRelationshipProperty> {ownerRelProp1};
            IDMRelationshipProperty ownerRelProp2 = AddRelProp(ownerRelProps);


            IList<IDMRelationshipProperty> reverseRelProps = new List<IDMRelationshipProperty>();
            IDMRelationshipProperty relatedRelProp1 = AddRelProp(reverseRelProps, ownerRelProp1.RelatedPropertyName,
                                                                 ownerRelProp1.OwnerPropertyName);
            IDMRelationshipProperty relatedRelProp2 = AddRelProp(reverseRelProps, ownerRelProp2.RelatedPropertyName,
                                                                 ownerRelProp2.OwnerPropertyName);

            DMSolutionPostLoadProcessor processor = GetProcessorWithAutoMocks();
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, reverseRelProps.Count());
            Assert.AreEqual(2, ownerRelProps.Count());

            AssertRelPropPropNamesSetUpAsReverse(ownerRelProp1, relatedRelProp1);
            AssertRelPropPropNamesSetUpAsReverse(ownerRelProp2, relatedRelProp2);
            //---------------Execute Test ----------------------
            processor.SetAllReverseRelProps(ownerRelProps, reverseRelProps);
            //---------------Test Result -----------------------
            AssertReverseRelPropsSetCorrectly(ownerRelProp1, relatedRelProp1);
            AssertReverseRelPropsSetCorrectly(ownerRelProp2, relatedRelProp2);
        }

        [Test]
        public void Test_ResetCardinality_ForAllRels_ShouldSetForAllRels()
        {
            //---------------Set up test pack-------------------
            List<IDMRelationship> col =new List<IDMRelationship>();
            DMRelationship relShouldBeSingle = GetStubDMRelationshipWithRRelAKTrue();
            relShouldBeSingle.Cardinality = Cardinality.Multiple;
            col.Add(relShouldBeSingle);

            DMRelationship relShouldBeSingle2 = GetStubDMRelationshipWithRRelPKTrue();
            relShouldBeSingle2.Cardinality = Cardinality.Multiple;
            col.Add(relShouldBeSingle2);

            DMRelationship relShouldNotBeChanged = GetStubDMRelationshipWithRRelAKFalseAndPKFalse();
            relShouldNotBeChanged.Cardinality = Cardinality.Multiple;
            col.Add(relShouldNotBeChanged);
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, relShouldBeSingle.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, relShouldBeSingle2.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, relShouldNotBeChanged.Cardinality);

            //---------------Execute Test ----------------------
            GetProcessorWithAutoMocks().ResetCardinality(col);
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relShouldBeSingle.Cardinality);
            Assert.AreEqual(Cardinality.Single, relShouldBeSingle2.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, relShouldNotBeChanged.Cardinality);
        }

        [Test]
        public void Test_SetParentDelteAction_WhenManyToOne_AndNeitherDeleteActionIsDoNothing_ShouldSetToDoNothing()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = CreateStubDMRelationship();
            relationship.Stub(dmRelationship => dmRelationship.IsManyToOne).Return(true);
            relationship.DeleteAction = DeleteParentAction.Prevent;
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationship.IsManyToOne);
            Assert.IsFalse(relationship.IsOneDeleteActionDoNothing);
            //---------------Execute Test ----------------------
            GetProcessorWithAutoMocks().ResetParentDeleteAction(relationship);
            //---------------Test Result -----------------------
            Assert.AreEqual(DeleteParentAction.DoNothing, relationship.DeleteAction);
        }

        [Test]
        public void Test_SetParentDelteAction_WhenNotManyToOne_AndDeleteActionNull_ShouldNotSet()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = CreateStubDMRelationship();
            relationship.Stub(dmRelationship => dmRelationship.IsManyToOne).Return(false);
            relationship.Stub(dmRelationship => dmRelationship.IsOneDeleteActionDoNothing).Return(true);
            Assert.IsTrue(relationship.IsOneDeleteActionDoNothing);
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.IsManyToOne);
            Assert.IsNull(relationship.DeleteAction);
            //---------------Execute Test ----------------------
            GetProcessorWithAutoMocks().ResetParentDeleteAction(relationship);
            //---------------Test Result -----------------------
            Assert.IsNull(relationship.DeleteAction);
        }
        [Test]
        public void Test_SetParentDelteAction_WhenManyToOne_AndDeleteActionNotNull_ShouldNotSet()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = CreateStubDMRelationship();
            relationship.Stub(dmRelationship => dmRelationship.IsManyToOne).Return(true);
            relationship.Stub(dmRelationship => dmRelationship.IsOneDeleteActionDoNothing).Return(true);
            relationship.DeleteAction = DeleteParentAction.DereferenceRelated;
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationship.IsManyToOne);
            Assert.IsNotNull(relationship.DeleteAction);
            Assert.IsTrue(relationship.IsOneDeleteActionDoNothing);
            //---------------Execute Test ----------------------
            GetProcessorWithAutoMocks().ResetParentDeleteAction(relationship);
            //---------------Test Result -----------------------
            Assert.AreEqual(DeleteParentAction.DereferenceRelated,  relationship.DeleteAction);
        }

/*
        private DMClass GetStubDMClassWithRelationshipColSet()
        {
            DMClass dmClass = MockRepository.GenerateStub<DMClass>(ConstructForFakes.True);
            var relationships = new FakeBusinessObjectCollection<DMRelationship>();
            dmClass.Stub(@class => @class.RelationshipsDM).Return(relationships);
            return dmClass;
        }*/

        private static DMRelationship GetStubDMRelationshipWithRRelAKFalseAndPKFalse()
        {
            DMRelationship reverseRelationship;
            DMRelationship relationship = CreateStubWithReverseRelationship(out reverseRelationship);
            SetAllPKProps(reverseRelationship, false);
            SetAllAKProps(reverseRelationship, false);
            return relationship;
        }

        private static DMRelationship GetStubDMRelationshipWithRRelPKTrue()
        {
            DMRelationship reverseRelationship;
            DMRelationship relationship = CreateStubWithReverseRelationship(out reverseRelationship);
            SetAllPKProps(reverseRelationship, true);
            SetAllAKProps(reverseRelationship, false);
            return relationship;
        }

        private static DMRelationship GetStubDMRelationshipWithRRelAKTrue()
        {
            DMRelationship reverseRelationship;
            DMRelationship relationship = CreateStubWithReverseRelationship(out reverseRelationship);
            SetAllPKProps(reverseRelationship, false);
            SetAllAKProps(reverseRelationship, true);
            return relationship;
        }

        private static DMRelationship CreateStubWithReverseRelationship(out DMRelationship reverseRelationship)
        {
            DMRelationship relationship = CreateStubDMRelationship();
            reverseRelationship = CreateStubDMRelationship();
            relationship.ReverseRelationship = reverseRelationship;
            return relationship;
        }
        private static DMRelationship CreateStubDMRelationship()
        {
            return MockRepository.GenerateStub<DMRelationship>(ConstructForFakes.True);
        }

        private static void SetAllPKProps(DMRelationship relationship, bool allPKProps)
        {
            relationship.Stub(rel => rel.HasAllPkProps()).Return(allPKProps);
        }
        private static void SetAllAKProps(DMRelationship relationship, bool allPKProps)
        {
            relationship.Stub(rel => rel.HasAllAkProps()).Return(allPKProps);
        }


        private static void AssertReverseRelPropsSetCorrectly(IDMRelationshipProperty ownerRelProp1,
                                                              IDMRelationshipProperty relatedRelProp1)
        {
            Assert.AreSame(ownerRelProp1, relatedRelProp1.ReverseRelationshipProperty);
            Assert.AreSame(relatedRelProp1, ownerRelProp1.ReverseRelationshipProperty);
        }

        private static void AssertRelPropsSetUpAsReverse(IDMRelationshipProperty relationshipProp,
                                                         IDMRelationshipProperty reverseRelProp)
        {
            Assert.IsNotNull(reverseRelProp);
            Assert.AreEqual(relationshipProp.RelatedPropertyName, reverseRelProp.OwnerPropertyName);
            Assert.AreEqual(relationshipProp.OwnerPropertyName, reverseRelProp.RelatedPropertyName);
            Assert.AreSame(relationshipProp, reverseRelProp.ReverseRelationshipProperty);
            Assert.AreSame(reverseRelProp, relationshipProp.ReverseRelationshipProperty);
        }

        private static IDMRelationshipProperty AddRelProp(IList<IDMRelationshipProperty> ownerRelProps)
        {
            return AddRelProp(ownerRelProps, GetRandomString(), GetRandomString());
        }

        private static string GetRandomString()
        {
            return TestUtilsShared.GetRandomString();
        }


        private static IDMRelationshipProperty GetMockRelationshipProperty(string ownerPropertyName,
                                                                           string relatedPropertyName)
        {
            IDMRelationshipProperty relatedRelProp = MockRepository.GenerateStub<IDMRelationshipProperty>();
            relatedRelProp.RelatedPropertyName = relatedPropertyName;
            relatedRelProp.OwnerPropertyName = ownerPropertyName;
            return relatedRelProp;
        }

        private static IDMRelationshipProperty AddRelProp(IDMRelationship relationship)
        {
            BusinessObjectCollection<DMRelationshipProperty> relProps =
                new FakeBusinessObjectCollection<DMRelationshipProperty>();
            relationship.Stub(rel => rel.RelationshipProperties).Return(relProps);

            return AddRelProp(relationship.RelationshipProperties, GetRandomString(), GetRandomString());
        }

// ReSharper disable UnusedMethodReturnValue.Local
        private static DMRelationshipProperty AddRelProp(IDMRelationship ownerRelationship, string ownerPropertyName,
                                                         string relatedPropertyName)
        {
            BusinessObjectCollection<DMRelationshipProperty> relProps =
                new FakeBusinessObjectCollection<DMRelationshipProperty>();
            ownerRelationship.Stub(rel => rel.RelationshipProperties).Return(relProps);
            return AddRelProp(ownerRelationship.RelationshipProperties, ownerPropertyName, relatedPropertyName);
        }
// ReSharper restore UnusedMethodReturnValue.Local

        private static DMRelationshipProperty AddRelProp(ICollection<DMRelationshipProperty> relProps,
                                                         string ownerPropertyName, string relatedPropertyName)
        {
            DMRelationshipProperty relatedRelProp = MockRepository.GenerateStub<DMRelationshipProperty>(ConstructForFakes.True);
            relatedRelProp.RelatedPropertyName = relatedPropertyName;
            relatedRelProp.OwnerPropertyName = ownerPropertyName;
    
            relProps.Add(relatedRelProp);
            return relatedRelProp;
        }

        private static IDMRelationshipProperty AddRelProp(ICollection<IDMRelationshipProperty> relProps,
                                                          string ownerPropertyName, string relatedPropertyName)
        {
            IDMRelationshipProperty relatedRelProp = GetMockRelationshipProperty(ownerPropertyName, relatedPropertyName);
            relProps.Add(relatedRelProp);
            return relatedRelProp;
        }

        private static IDMRelationshipProperty GetMockRelationshipProperty()
        {
            IDMRelationshipProperty relationshipProperty = MockRepository.GenerateStub<IDMRelationshipProperty>();
            relationshipProperty.OwnerPropertyName = GetRandomString();
            relationshipProperty.RelatedPropertyName = GetRandomString();
            return relationshipProperty;
        }

        private static List<IDMClass> GetColWithOneRelatedClass(string relatedAssemblyName, string relatedClassName)
        {
            List<IDMClass> col = new List<IDMClass>();
            var relatedClass = GetMockClass(relatedAssemblyName, relatedClassName);
            col.Add(relatedClass);
            return col;
        }

        private static DMRelationship SetMockRelationship(string relatedClasssAssemblyName, string relatedClassName, IDMClass ownerClass, string relationshipName, string reverseRelationshiName)
        {
            SetRelationshipsToEmpty(ownerClass);
            var relationship = MockRepository.GenerateStub<DMRelationship>(ConstructForFakes.True);
            relationship.RelationshipName = relationshipName;
            relationship.ReverseRelationshipName = reverseRelationshiName;
            relationship.RelatedAssemblyName = relatedClasssAssemblyName;
            relationship.RelatedClassName = relatedClassName;
            ownerClass.RelationshipsDM.Add(relationship);
            DMRelationship reverseRel = relationship;
            return reverseRel;
        }

        private static DMRelationship SetRelationship(IDMClass relatedClass, string ownerClassAssemblyName, string relatedClassName, string relationshipName, string reverseRelationshiName)
        {
            SetRelationshipsToEmpty(relatedClass);
            DMRelationship reverseRel = AddRelationship(relatedClass, ownerClassAssemblyName, relatedClassName, relationshipName, reverseRelationshiName);
            return reverseRel;
        }

        private static IDMClass GetMockClass(string assemblyName, string className)
        {
            var mockClass = GetMockClass();
            mockClass.ClassNameBO = className;
            mockClass.AssemblyName = assemblyName;
            //mockClass.Stub(@class => @class.AssemblyName).Return(assemblyName);
            return mockClass;
        }

        private static void SetRelationshipsToEmpty(IDMClass relatedClass)
        {
            relatedClass.Stub(dmClass => dmClass.RelationshipsDM).Return(
                new FakeBusinessObjectCollection<DMRelationship>());
        }

        private static DMRelationship AddRelationship(IDMClass relatedClass, string relatedAssemblyName, string relatedClassName, string relationshipName, string reverseRelationshiName)
        {
            var reverseRel = new DMRelationship(null)
                                 {
                                     RelationshipName = relationshipName,
                                     ReverseRelationshipName = reverseRelationshiName,
                                     RelatedClassName = relatedClassName,
                                     RelatedAssemblyName = relatedAssemblyName
                                 };
            relatedClass.RelationshipsDM.Add(reverseRel);
            return reverseRel;
        }

        private static IDMRelationship GetMockRelationshipWithNamesSet()
        {
            IDMRelationship relationship = GetMockRelationship();
            relationship.Stub(dmRelationship => dmRelationship.OwnerClassName).Return(GetRandomString());
            relationship.ReverseRelationshipName = GetRandomString();
            relationship.RelationshipName = GetRandomString();
            relationship.RelatedClassName = GetRandomString();
            relationship.Stub(relationship1 => relationship1.OwnerClassAssemblyName).Return(GetRandomString());
            return relationship;
        }

        private static void SetRelationshipPropWithNoItems(IDMRelationship relationship)
        {
            BusinessObjectCollection<DMRelationshipProperty> col =
                new BusinessObjectCollection<DMRelationshipProperty>();
            relationship.Stub(dmRelationship => dmRelationship.RelationshipProperties).Return(col);
        }

        private static IDMClass GetMockClassWithTwoProp(string propertyName1, string propertyName2)
        {
            IDMClass stubClass = MockRepository.GenerateStub<IDMClass>();
            stubClass.Stub(dmClass => dmClass.GetDMProperty(propertyName1)).Return(new DMProperty());
            stubClass.Stub(dmClass => dmClass.GetDMProperty(propertyName2)).Return(new DMProperty());
            return stubClass;
        }

        private static IDMClass GetMockClassWithOneProp(string propertyName)
        {
            IDMClass stubClass = MockRepository.GenerateStub<IDMClass>();
            stubClass.Stub(dmClass => dmClass.GetDMProperty(propertyName)).Return(
                new DMProperty());
            return stubClass;
        }


        private static IDMRelationship GetReverseRelationship()
        {
            IDMRelationship reverseRelationship = GetMockRelationship();
            SetRelationshipPropWithNoItems(reverseRelationship);
            return reverseRelationship;
        }

        private static void AssertRelPropPropNamesSetUpAsReverse(IDMRelationshipProperty ownerRelProp1,
                                                                 IDMRelationshipProperty relatedRelProp1)
        {
            Assert.AreEqual(ownerRelProp1.OwnerPropertyName, relatedRelProp1.RelatedPropertyName);
            Assert.AreEqual(ownerRelProp1.RelatedPropertyName, relatedRelProp1.OwnerPropertyName);
        }


        private static void AssertReverseRelPropsNames(IEnumerable<DMRelationshipProperty> relProps,
                                                       IEnumerable<DMRelationshipProperty> reverseRelProps)
        {
            foreach (var relProp in relProps)
            {
                var relatedPropertyName = relProp.RelatedPropertyName;
                var reverseRelProp = reverseRelProps.First(property => property.OwnerPropertyName == relatedPropertyName);
                AssertRelPropsSetUpAsReverse(relProp, reverseRelProp);
            }
        }

        private static DMRelationshipProperty SetRelationshipPropsWithOneItem(IDMRelationship relationship)
        {
            BusinessObjectCollection<DMRelationshipProperty> col =
                new BusinessObjectCollection<DMRelationshipProperty>();
            var relpProp = CreateRandomRelProp();
            col.Add(relpProp);
            relationship.Stub(dmRelationship => dmRelationship.RelationshipProperties).Return(col);
            return relpProp;
        }

        private static IEnumerable<DMRelationshipProperty> SetRelationshipPropsWithTwoItem(IDMRelationship relationship)
        {
            BusinessObjectCollection<DMRelationshipProperty> col = new BusinessObjectCollection<DMRelationshipProperty>
                                                                       {
                                                                           CreateRandomRelProp(),
                                                                           CreateRandomRelProp()
                                                                       };
            relationship.Stub(dmRelationship => dmRelationship.RelationshipProperties).Return(col);
            return col;
        }

        private static DMRelationshipProperty CreateRandomRelProp()
        {
            var dmRelationshipProperty = new DMRelationshipProperty(null)
                                             {
                                                 OwnerPropertyName = GetRandomString(),
                                                 RelatedPropertyName = GetRandomString()
                                             };
            return dmRelationshipProperty;
        }

        private static void SetSingle(IDMRelationship relationship)
        {
            relationship.Stub(dmRelationship => dmRelationship.IsSingle).Return(true);
            relationship.Stub(dmRelationship => dmRelationship.IsMultiple).Return(false);
        }

        private static void SetMultiple(IDMRelationship relationship)
        {
            relationship.Stub(dmRelationship => dmRelationship.IsSingle).Return(false);
            relationship.Stub(dmRelationship => dmRelationship.IsMultiple).Return(true);
        }

        private static DMSolutionPostLoadProcessor GetProcessorWithAutoMocks()
        {
            IUnityContainer container = new AutoMockingUnityContainer();
            return new DMSolutionPostLoadProcessor(container);
        }

        private static DMSolutionPostLoadProcessor GetProcessor()
        {
            IUnityContainer container = new UnityContainer();
            container.RegisterType<IDMRelationship, DMRelationship>();
            return new DMSolutionPostLoadProcessor(container);
        }

        private static IDMRelationship GetMockRelationship()
        {
            var dmRelationship = MockRepository.GenerateStub<IDMRelationship>();
            return dmRelationship;
        }

        private static IDMClass GetMockClass()
        {
            var relatedClass = MockRepository.GenerateStub<IDMClass>();
            return relatedClass;
        }

        [Test]
        public void TestAccept_WhenLoadingClassWithSuperClass_ShouldLinkDMClassObjectsTogether()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            const string classDefsXml =
                @"
                <classes>
					<class name=""TestBaseClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestBaseClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestBaseClassID""/>
                        </primaryKey>
					</class>
                    <class name=""TestSubClass"" assembly=""FireStarter.Test.Logic""  >
					    <superClass class=""TestBaseClass"" assembly=""FireStarter.Test.Logic"" />
					    <property  name=""TestSubClassID"" />
                        <primaryKey>
                            <prop name=""TestSubClassID""/>
                        </primaryKey>
				    </class>
				</classes>";
            ClassDefCol classDefs = loader.LoadClassDefs(classDefsXml);
            DMClass baseClass =
                (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestBaseClass"];
            DMClass subClass =
                (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestSubClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();

            //---------------Assert PreConditions---------------
            Assert.IsNotNull(subClass.InheritanceSuperClassRelationship);
            Assert.IsNull(subClass.InheritanceSuperClassRelationship.SuperClassID);
            //            Assert.IsNull(subClass.InheritanceSuperClassRelationship.SuperClass);
            Assert.AreEqual(0, baseClass.SubClassRelationships.Count);
            //            Assert.AreEqual(baseClass.);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(baseClass.Solution);

            //---------------Test Result -----------------------
            Assert.IsNotNull(subClass.InheritanceSuperClassRelationship.SuperClassID);
            Assert.AreEqual(1, baseClass.SubClassRelationships.Count);
            Assert.IsNotNull(baseClass.SubClassRelationships[0].SubClass);
        }
        
        [Test]
        public void TestAccept_WhenLoadingClassWithSuperClass_WithIdentityProp_ShouldLinkIdentityProp()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            const string classDefsXml =
                @"
                <classes>
					<class name=""TestBaseClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestBaseClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestBaseClassID""/>
                        </primaryKey>
					</class>
                    <class name=""TestSubClass"" assembly=""FireStarter.Test.Logic""  >
					    <superClass class=""TestBaseClass"" assembly=""FireStarter.Test.Logic"" id=""TestBaseClassIdentity"" />
					    <property  name=""TestSubClassID"" />
                        <property  name=""TestBaseClassIdentity"" />
                        <primaryKey>
                            <prop name=""TestSubClassID""/>
                        </primaryKey>
				    </class>
				</classes>";
            ClassDefCol classDefs = loader.LoadClassDefs(classDefsXml);
            DMClass baseClass =
                (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestBaseClass"];
            DMClass subClass =
                (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestSubClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();

            //---------------Assert PreConditions---------------
            Assert.IsNotNull(subClass.InheritanceSuperClassRelationship);
            Assert.IsNull(subClass.InheritanceSuperClassRelationship.SuperClassID);
            Assert.IsNull(subClass.InheritanceSuperClassRelationship.IdentityPropertyID);
            Assert.AreEqual(0, baseClass.SubClassRelationships.Count);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(baseClass.Solution);
            //---------------Test Result -----------------------
            Assert.IsNotNull(subClass.InheritanceSuperClassRelationship.SuperClassID);
            Assert.IsNotNull(subClass.InheritanceSuperClassRelationship.IdentityPropertyID);
            var identityProperty = subClass.GetDMProperty("TestBaseClassIdentity");
            Assert.IsNotNull(identityProperty);
            Assert.AreSame(identityProperty, subClass.InheritanceSuperClassRelationship.IdentityProperty);
        }

        [Test]
        public void TestAccept_WhenLoadingClassWithRelatedClass_ShouldLinkDMClassObjectsTogether()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClassXml);
            DMClass dmClass = (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();

            //---------------Assert PreConditions---------------        
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.IsNull(dmClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreNotSame(relatedClass, dmClass.RelatedRelationships[0].RelatedClass);

            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            Assert.IsNull(relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreNotSame(dmClass, relatedClass.RelatedRelationships[0].RelatedClass);

            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.IsNotNull(dmClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(relatedClass, dmClass.RelatedRelationships[0].RelatedClass);

            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            Assert.IsNotNull(relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(dmClass, relatedClass.RelatedRelationships[0].RelatedClass);
        }


        private const string TestClassWithRelatedClassXml =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                            reverseRelationship=""TestClasses""
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                            reverseRelationship=""TestRelatedClass""
                        >
                            <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";


        private const string TestClassWithRelatedClass_NoReverseRelationship_Xml =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
				    </class>
				</classes>";


        [Test]
        public void TestAccept_WhenLoadingClassWithRelatedClass_ShouldLinkDMPropertyObjectsTogether()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClassXml);
            DMClass dmClass = (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship dmClassRelationship = dmClass.RelatedRelationships[0];
            DMRelationship relatedClassRelationship = relatedClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------        
            Assert.AreNotSame(relatedClass, dmClassRelationship.RelatedClass);
            Assert.AreNotSame(dmClass, relatedClassRelationship.RelatedClass);

            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, dmClassRelationship.RelatedClass);
            Assert.AreSame(dmClass, relatedClassRelationship.RelatedClass);

            Assert.AreEqual(1, dmClassRelationship.RelationshipProperties.Count);

            Assert.AreSame(dmClass.GetDMProperty("TestRelatedClassID"),
                           dmClassRelationship.RelationshipProperties[0].OwnerProperty);
            Assert.AreSame(relatedClassRelationship.RelationshipProperties[0],
                           dmClassRelationship.RelationshipProperties[0].ReverseRelationshipProperty);

            Assert.AreSame(relatedClass.GetDMProperty("TestRelatedClassID"),
                           relatedClassRelationship.RelationshipProperties[0].OwnerProperty);
            Assert.AreSame(dmClassRelationship.RelationshipProperties[0],
                           relatedClassRelationship.RelationshipProperties[0].ReverseRelationshipProperty);
        }

/*

        [Test]
        public void TestAccept_BusinessObjectLookupListIsLinkedToDMClass()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            const string classDefsXml = @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestLookupID"" type=""Guid"" >
                            <businessObjectLookupList class=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic"" />
                        </property>
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
				    </class>
				</classes>";
            ClassDefCol classDefs = loader.LoadClassDefs(classDefsXml);
            DMClass @class = (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMClass dmProperty = (DMClass) @class.GetDMProperty("TestLookupID");
            DMLookupListBusinessObject lookupList = (DMLookupListBusinessObject) dmProperty.LookupList;

            //---------------Assert PreConditions---------------
            Assert.IsNull(lookupList.DMClass);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmSolution);
            //---------------Test Result -----------------------
            Assert.IsNotNull(lookupList.DMClass);
            //---------------Tear Down -------------------------          
        }
*/

        [Test]
        public void TestAccept_WhenLoadingClassWithRelatedClass_NoReverseRelationship_ShouldLinkDMRelationshipObjectsTogether()
        {
            //---------------Set up test pack-------------------
            const string classDefXML = TestClassWithRelatedClass_NoReverseRelationship_Xml;
            ClassDefCol classDefs = GetClassDefs(classDefXML);
            DMClass ownerClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship ownerClassRel = ownerClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------        
            Assert.AreNotSame(relatedClass, ownerClassRel.RelatedClass);
            Assert.AreEqual(0, relatedClass.RelatedRelationships.Count);
            Assert.AreEqual(1, ownerClass.RelatedRelationships.Count);
            Assert.AreEqual(relatedClass.ClassNameBO, ownerClassRel.RelatedClassName);
            Assert.IsNullOrEmpty(ownerClassRel.ReverseRelationshipName);
            Assert.AreEqual(1, ownerClassRel.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(ownerClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, ownerClassRel.RelatedClass);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            DMRelationship relatedClassRelationship = relatedClass.RelatedRelationships[0];
            Assert.AreSame(ownerClass, relatedClassRelationship.RelatedClass);
            Assert.IsNotNull(relatedClassRelationship.ReverseRelationship);
            Assert.IsNotNull(relatedClassRelationship.RelationshipName);
            Assert.IsNotNull(relatedClassRelationship.ReverseRelationshipName);
            Assert.AreEqual(Cardinality.Multiple, relatedClassRelationship.Cardinality);
            Assert.AreEqual(1, ownerClassRel.RelationshipProperties.Count);

            Assert.AreSame(ownerClass.GetDMProperty("TestRelatedClassID"),
                           ownerClassRel.RelationshipProperties[0].OwnerProperty);

            Assert.AreEqual(1, relatedClassRelationship.RelationshipProperties.Count);
            Assert.AreEqual(1, ownerClassRel.RelationshipProperties.Count);
            Assert.AreSame(relatedClassRelationship.RelationshipProperties[0],
                           ownerClassRel.RelationshipProperties[0].ReverseRelationshipProperty);

            Assert.AreSame(relatedClass.GetDMProperty("TestRelatedClassID"),
                           relatedClassRelationship.RelationshipProperties[0].OwnerProperty);
            Assert.AreSame(ownerClassRel.RelationshipProperties[0],
                           relatedClassRelationship.RelationshipProperties[0].ReverseRelationshipProperty);
        }

        private static ClassDefCol GetClassDefs(string classDefXML)
        {
            DMSolution dmSolution = GetDMSolution();
            return LoadClassDefs(dmSolution, classDefXML);
        }

        private static ClassDefCol LoadClassDefs(IDMSolution dmSolution, string classDefXML)
        {
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            return loader.LoadClassDefs(classDefXML);
        }


/*        private const string TestClassWithRelatedClass_SingleRelationship_NoReverseRelationship_Xml =
               @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID2"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass1"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
                        <relationship 
						    name=""TestRelatedClass2"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
						        <relatedProperty property=""TestRelatedClassID2"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
				    </class>
				</classes>";*/


        [Test]
        public void
            TestAccept_WhenMultipelRel_WhenLoadingClassWithRelatedClass_NoReverseRelationship_ShouldLinkDMRelationshipObjectsTogether
            ()
        {
            //---------------Set up test pack-------------------
            const string classDefXML = TestClassWithRelatedClass_MultipleRelationship_NoReverseRelationship_Xml;
            ClassDefCol classDefs = GetClassDefs(classDefXML);
            DMClass ownerClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship ownerClassRel = ownerClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------        
            Assert.AreNotSame(relatedClass, ownerClassRel.RelatedClass);
            Assert.AreEqual(0, relatedClass.RelatedRelationships.Count);
            Assert.AreEqual(1, ownerClass.RelatedRelationships.Count);
            Assert.AreEqual(relatedClass.ClassNameBO, ownerClassRel.RelatedClassName);
            Assert.IsNullOrEmpty(ownerClassRel.ReverseRelationshipName);
            Assert.AreEqual(1, ownerClassRel.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(ownerClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, ownerClassRel.RelatedClass);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            DMRelationship relatedClassRelationship = relatedClass.RelatedRelationships[0];
            Assert.AreSame(ownerClass, relatedClassRelationship.RelatedClass);
            Assert.IsNotNull(relatedClassRelationship.ReverseRelationship);
            Assert.IsNotNull(relatedClassRelationship.RelationshipName);
            Assert.IsNotNull(relatedClassRelationship.ReverseRelationshipName);
            Assert.AreEqual(Cardinality.Single, relatedClassRelationship.Cardinality);
            Assert.AreEqual(1, ownerClassRel.RelationshipProperties.Count);

            Assert.AreSame(ownerClass.GetDMProperty("TestRelatedClassID"),
                           ownerClassRel.RelationshipProperties[0].OwnerProperty);

            Assert.AreEqual(1, relatedClassRelationship.RelationshipProperties.Count);
            Assert.AreEqual(1, ownerClassRel.RelationshipProperties.Count);
            Assert.AreSame(relatedClassRelationship.RelationshipProperties[0],
                           ownerClassRel.RelationshipProperties[0].ReverseRelationshipProperty);

            Assert.AreSame(relatedClass.GetDMProperty("TestRelatedClassID"),
                           relatedClassRelationship.RelationshipProperties[0].OwnerProperty);
            Assert.AreSame(ownerClassRel.RelationshipProperties[0],
                           relatedClassRelationship.RelationshipProperties[0].ReverseRelationshipProperty);
        }

        private const string TestClassWithRelatedClass_MultipleRelationship_NoReverseRelationship_Xml =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID2"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClasses"" 
						    type=""multiple"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
				    </class>
				</classes>";


        private const string TestClassWithRelatedClass_SingleRelationship_NoReverseRelationship_Xml =
            @"
                <classes>
					<class name=""TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID2"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass1"" 
						    type=""single"" 
						    relatedClass=""TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
                        <relationship 
						    name=""TestRelatedClass2"" 
						    type=""single"" 
						    relatedClass=""TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
						        <relatedProperty property=""TestRelatedClassID2"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
				    </class>
				</classes>";

        [Test]
        public void
            TestAccept_WhenLoadingClassWithRelatedClass_SingleRelationship_NoReverseRelationship_ShouldLinkDMRelationshipObjectsTogether
            ()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs =
                loader.LoadClassDefs(TestClassWithRelatedClass_SingleRelationship_NoReverseRelationship_Xml);
            DMClass dmClass = (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();


            //---------------Assert PreConditions---------------  
            Assert.AreEqual(2, dmClass.RelatedRelationships.Count);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            DMRelationship @classRelationship = dmClass.RelatedRelationships[0];
            DMRelationship relatedRelationship = relatedClass.RelatedRelationships[0];
            Assert.AreSame(@classRelationship, relatedRelationship.ReverseRelationship);
            Assert.AreSame(relatedRelationship, @classRelationship.ReverseRelationship);

            Assert.AreSame(relatedClass, @classRelationship.RelatedClass);
            Assert.AreEqual(2, relatedClass.RelatedRelationships.Count);

            DMRelationship relatedClassRelationship = relatedRelationship;
            Assert.AreSame(dmClass, relatedClassRelationship.RelatedClass);

            Assert.AreEqual(1, @classRelationship.RelationshipProperties.Count);

            Assert.AreSame(dmClass.GetDMProperty("TestRelatedClassID"),
                           @classRelationship.RelationshipProperties[0].OwnerProperty);
            Assert.AreSame(relatedClassRelationship.RelationshipProperties[0],
                           @classRelationship.RelationshipProperties[0].ReverseRelationshipProperty);

            Assert.AreSame(relatedClass.GetDMProperty("TestRelatedClassID"),
                           relatedClassRelationship.RelationshipProperties[0].OwnerProperty);
            Assert.AreSame(@classRelationship.RelationshipProperties[0],
                           relatedClassRelationship.RelationshipProperties[0].ReverseRelationshipProperty);
        }


        private const string TestClassWithRelatedClassXml_RelationshipNotNamed =
            @"
                <classes>
					<class name=""TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                    </class>
                    <class name=""TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""TestClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                            reverseRelationship=""TestRelatedClass""
                        >
                            <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";

/*
        private const string TestClassWithRelatedClassXml_RelationshipNotNamed =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                    </class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                            reverseRelationship=""TestRelatedClass""
                        >
                            <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";*/

        [Test]
        public void TestAccept_Process_WhenMultipleWithNoReverseRelationship_ShouldNameReverseRelationship()
        {
            //---------------Set up test pack-------------------
            const string classDefXML = TestClassWithRelatedClassXml_RelationshipNotNamed;
            ClassDefCol classDefs = GetClassDefs(classDefXML);
//            DMSolution dmSolution = GetDMSolution();
/*            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClassXml_RelationshipNotNamed);*/
            DMClass @class = (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            var testClassesRelationship = relatedClass.RelatedRelationships.First();
            //---------------Assert PreConditions---------------    
            Assert.AreEqual(2, classDefs.Count);
            Assert.AreEqual(0, @class.RelatedRelationships.Count);
            Assert.AreEqual("TestClass", @class.ClassNameBO);
            Assert.IsNotNull(testClassesRelationship);
            Assert.AreEqual("TestRelatedClass", relatedClass.ClassNameBO);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(@class.Solution);
            //---------------Test Result -----------------------
            DMRelationship createdRelationship = @class.RelatedRelationships[0];
            Assert.AreEqual("TestRelatedClass", createdRelationship.RelationshipName);
            Assert.AreSame(createdRelationship, testClassesRelationship.ReverseRelationship);
            Assert.AreSame(createdRelationship.ReverseRelationship, testClassesRelationship);
        }

        [Test]
        public void Test_ClassDefLoader_LoadsClassCorrectly()
        {
            //---------------Set up test pack-------------------
            //---------------Set up test pack-------------------
            const string classDefXML = TestClassWithRelatedClassXml_RelationshipNotNamed;
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            ClassDefCol classDefs = loader.LoadClassDefs(classDefXML);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, classDefs.Count);
            DMClass ownerClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            Assert.AreEqual(0, ownerClass.RelatedRelationships.Count);
            Assert.AreEqual("TestClass", ownerClass.ClassNameBO);

            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            Assert.AreEqual("TestRelatedClass", relatedClass.ClassNameBO);
        }

        private const string TestClassWithRelatedClassXml_OnlyOneReverseRelationshipIndicated =
            @"
                <classes>
					<class name=""TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                            reverseRelationship=""TestClasses""
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""TestClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
                            <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";

/*        private const string TestClassWithRelatedClassXml_OnlyOneReverseRelationshipIndicated =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                            reverseRelationship=""TestClasses""
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
                            <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";*/

        [Test]
        public void Test_LoadAccept_WhenClassWithRelatedClassXml_OnlyOneReverseRelationshipIndicated_ShouldLoadEachRel()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ClassDefCol classDefs =
                loader.LoadClassDefs(TestClassWithRelatedClassXml_OnlyOneReverseRelationshipIndicated);
            //---------------Test Result -----------------------
            IClassDef classDef = classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            IClassDef relatedClassDef =
                classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];

            Assert.AreEqual(1, classDef.RelationshipDefCol.Count);
            Assert.AreEqual(1, relatedClassDef.RelationshipDefCol.Count);
        }

        [Test]
        public void TestAccept_LinkReverseRelationshipsEvenIfOnlyOneIsIndicated()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();

            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs =
                loader.LoadClassDefs(TestClassWithRelatedClassXml_OnlyOneReverseRelationshipIndicated);
            DMClass dmClass = (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship relatedRelationship = dmClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------           
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            Assert.AreNotSame(relatedRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreNotSame(relatedRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            Assert.AreSame(relatedRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(relatedRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
        }


        private const string TestClassWithRelatedClass_NeitherRevRelIndicated =
            @"
                <classes>
					<class name=""TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic""
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""TestClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
                            <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";

        [Test]
        public void TestAccept_Process_Relationships_WhenNeitherIndicated_ShouldLink()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();

            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClass_NeitherRevRelIndicated);
            DMClass dmClass = (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship relatedRelationship = dmClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------   
            
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            Assert.AreNotSame(relatedRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreNotSame(relatedRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            Assert.AreSame(relatedRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(relatedRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
        }

        private const string TestClassWithRelatedClass_BothIndicatedPlusPlusExtraRel =
            @"<classes>
               <class name=""TestClass"" assembly=""FireStarter.Test.Logic"" displayName=""TestClass"">
                    <property name=""TestClassID"" type=""Guid"" readWriteRule=""WriteNew"" compulsory=""true"" />
                    <primaryKey>
                      <prop name=""TestClassID"" />
                    </primaryKey>
                    <relationship name=""TestRelatedClasss"" type=""single"" relatedClass=""TestRelatedClass"" reverseRelationship=""TestClass"" relatedAssembly=""FireStarter.Test.Logic"">
                      <relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
                    </relationship>
                  </class>
                 
                 <class name=""TestRelatedClass"" assembly=""FireStarter.Test.Logic"">
                    <property name=""TestRelatedClassID"" type=""Guid"" readWriteRule=""WriteNew"" compulsory=""true"" />
                    <property name=""TestClassID"" type=""Guid"" compulsory=""true"">
                      <businessObjectLookupList class=""TestClass"" assembly=""FireStarter.Test.Logic"" sort=""Location"" />
                    </property>
                    <primaryKey>
                      <prop name=""TestRelatedClassID"" />
                    </primaryKey>
                    <relationship name=""TestClass"" type=""single"" relatedClass=""TestClass"" reverseRelationship=""TestRelatedClasss"" relatedAssembly=""FireStarter.Test.Logic"" deleteAction=""DoNothing"">
                      <relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
                    </relationship>
                 </class>

                 
                 <class name=""TestRelatedClass2"" assembly=""FireStarter.Test.Logic"" >
                    <property name=""TestRelatedClass2ID"" type=""Guid"" readWriteRule=""WriteNew"" compulsory=""true"" />
                    <property name=""TestClassID"" type=""Guid"" compulsory=""true""/>
                    <primaryKey>
                      <prop name=""TestRelatedClass2ID"" />
                    </primaryKey>
                    <relationship name=""TestClass"" type=""single"" relatedClass=""TestClass"" reverseRelationship=""TestRelatedClass2s"" relatedAssembly=""FireStarter.Test.Logic"" deleteAction=""DoNothing"">
                      <relatedProperty property=""TestClassID"" relatedProperty=""TestClassID"" />
                    </relationship>
                 </class>
            </classes>";

        [Test]
        public void TestAccept_Process_Relationships_WhenBothAreIndicated_ShouldLink()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();

            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClass_BothIndicatedPlusPlusExtraRel);
            DMClass dmClass = (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship ownerRelationship = dmClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------  
            Assert.IsFalse(ownerRelationship.HasAllAkProps());
            Assert.IsFalse(ownerRelationship.HasAllAkProps());
            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            Assert.AreNotSame(ownerRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreNotSame(ownerRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, relatedClass.RelatedRelationships[0].Cardinality);

            Assert.AreSame(ownerRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(ownerRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
        }

        private const string TestClassWithRelatedClass_NoReverseRelationship_FKIsUC_RevRelShouldBSingle_Xml =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <key name=""UC"">
                          <prop name=""TestRelatedClassID"" />
                        </key>
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" 
                        >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
				    </class>
				</classes>";

        [Test]
        public void TestAccept_Process_WhenFKIsUCShouldSetReverseRelToSingle()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();

            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClass_NoReverseRelationship_FKIsUC_RevRelShouldBSingle_Xml);
            DMClass dmClass = (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship ownerRelationship = dmClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------       
            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(0, relatedClass.RelatedRelationships.Count);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, relatedClass.RelatedRelationships[0].Cardinality);

            Assert.AreSame(ownerRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(ownerRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
        }


        private const string TestClassWithRelatedClass_NoReverseRelationship_FKIsUC_ButRRelIsMultiple_Xml =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <key name=""UC"">
                          <prop name=""TestRelatedClassID"" />
                        </key>
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                     <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestClass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";

        [Test]
        public void TestAccept_Process_WhenFKIsUCButRevRelIsDeclaredMultiple_DoesNotChangeCardinality()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();

            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClass_NoReverseRelationship_FKIsUC_ButRRelIsMultiple_Xml);
            DMClass dmClass = (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMClass relatedClass =
                (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestRelatedClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship ownerRelationship = dmClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------       
            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, relatedClass.RelatedRelationships[0].Cardinality);

            Assert.AreSame(ownerRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(ownerRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);
        }


        private const string TestClassWithRelatedClass_RelatedClassNameNotCapitalisedCorrectly_Xml =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""TestRelatedClassID"" type=""Guid"" />
                        <key name=""UC"">
                          <prop name=""TestRelatedClassID"" />
                        </key>
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
                        <relationship 
						    name=""TestRelatedClass"" 
						    type=""single"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.TestRelatedclass"" 
						    relatedAssembly=""FireStarter.Test.Logic"" >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
					</class>
                    <class name=""FireStarter.Test.Logic.Loaders.TestRelatedClass"" assembly=""FireStarter.Test.Logic""  >
					    <property  name=""TestRelatedClassID"" />
                        <primaryKey>
                            <prop name=""TestRelatedClassID""/>
                        </primaryKey>
                     <relationship 
						    name=""TestClasses"" 
						    type=""multiple"" 
						    relatedClass=""FireStarter.Test.Logic.Loaders.Testclass"" 
						    relatedAssembly=""FireStarter.Test.logic"" >
						        <relatedProperty property=""TestRelatedClassID"" relatedProperty=""TestRelatedClassID"" />
    					</relationship>
				    </class>
				</classes>";

        [Test]
        public void TestAccept_Process_WhenRelatedClassNameNotCapitalisedCorrectly_ShouldImport()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();

            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithRelatedClass_RelatedClassNameNotCapitalisedCorrectly_Xml);
            DMClass dmClass = (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            const string relatedClassName = "FireStarter.Test.Logic.Loaders.TestRelatedClass";
            DMClass relatedClass =
                (DMClass)classDefs["FireStarter.Test.Logic", relatedClassName];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            DMRelationship ownerRelationship = dmClass.RelatedRelationships[0];

            //---------------Assert PreConditions---------------       
            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);
            Assert.AreNotEqual(relatedClassName, ownerRelationship.RelatedClassName);
            Assert.AreEqual(DeleteParentAction.Prevent, ownerRelationship.DeleteAction);
            //---------------Execute Test ----------------------
            processor.ProcessSolution(dmClass.Solution);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.RelatedRelationships.Count);
            Assert.AreEqual(1, relatedClass.RelatedRelationships.Count);

            Assert.AreEqual(Cardinality.Single, ownerRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, relatedClass.RelatedRelationships[0].Cardinality);

            Assert.AreSame(ownerRelationship, relatedClass.RelatedRelationships[0].ReverseRelationship);
            Assert.AreSame(ownerRelationship.ReverseRelationship, relatedClass.RelatedRelationships[0]);

            Assert.AreEqual(DeleteParentAction.DoNothing, ownerRelationship.DeleteAction);
        }

        private static DMSolution GetDMSolution()
        {
            SolutionCreator solutionCreator = new SolutionCreator();
            DMSolution dmSolution = solutionCreator.CreateSolution();
            dmSolution.Assemblies.ForEach(assembly => assembly.MarkForDelete());
            return dmSolution;
        }

        private const string TestClassWithUniqueConstraintWithNoName =
            @"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""Bob"" />
                        <key>
                            <prop name=""Bob"" />
                        </key>
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
					</class>
				</classes>";




        [Test]
        public void TestAccept_SetDefaultNameForUniqueConstraintsWithoutNames()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithUniqueConstraintWithNoName);
            DMClass @class = (DMClass) classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();

            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            processor.ProcessSolution(@class.Solution);

            //---------------Test Result -----------------------
            DMUniqueConstraint constraint = @class.UniqueConstraints[0];
            Assert.AreEqual("UC1", constraint.UniqueConstraintName);
            //---------------Tear Down -------------------------          
        }

        private const string TestClassWithDisplayName =
@"
                <classes>
					<class name=""FireStarter.Test.Logic.Loaders.TestClass"" assembly=""FireStarter.Test.Logic"" >
						<property  name=""TestClassID"" type=""Guid"" />
                        <property name=""Bob"" displayName = ""Bob the Builder""/>
                        <key>
                            <prop name=""Bob"" />
                        </key>
                        <primaryKey>
                            <prop name=""TestClassID""/>
                        </primaryKey>
					</class>
				</classes>";

        [Test]
        public void TestAccept_SetDisplayNameForProperties()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = GetDMSolution();
            XmlClassDefsLoader loader = new XmlClassDefsLoader("", new DtdLoader(), new FMDefClassFactory(dmSolution));
            ClassDefCol classDefs = loader.LoadClassDefs(TestClassWithDisplayName);
            DMClass @class = (DMClass)classDefs["FireStarter.Test.Logic", "FireStarter.Test.Logic.Loaders.TestClass"];
            DMSolutionPostLoadProcessor processor = GetProcessor();
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            processor.ProcessSolution(@class.Solution);

            //---------------Test Result -----------------------
            IDMProperty dmProperty1 = @class.GetDMProperty("TestClassID");
            Assert.AreEqual("Test Class ID", dmProperty1.DisplayName);
            IDMProperty dmProperty2 = @class.GetDMProperty("Bob");
            Assert.AreEqual("Bob the Builder", dmProperty2.DisplayName);
            //---------------Tear Down -------------------------          
        }


    }

//
//    internal class FakeFMDefClassFactory : FMDefClassFactory
//    {
//        public FakeFMDefClassFactory() : base(MockRepository.GenerateMock<IDMSolution>())
//        {
//        }
//    }

    public class TestBaseClass : BusinessObject
    {
    }


// ReSharper disable UnusedMember.Global
    public class TestSubClass : TestBaseClass
    {
    }

    public class TestClass : BusinessObject
    {
    }

    public class TestRelatedClass : BusinessObject
    {
    }
    public class TestRelatedClass2 : BusinessObject
    {
    }

    // ReSharper restore InconsistentNaming

    internal class FakeDMSolutionPostLoadProcessor : DMSolutionPostLoadProcessor
    {
        public FakeDMSolutionPostLoadProcessor(IUnityContainer container) : base(container)
        {
        }
        public void SetAllClassses(List<IDMClass> allClasses)
        {
            AllClasses = allClasses;
        }
    }

}